var vm = new Vue({
    el:"#app",
    data(){
        return {
            ThemeList:[],
            SelectInfo:{
                Theme:'',
                nowdate:'',
                Store:'',
                Bm:'',
                UserNo:'',
                UserName:'',
            },
            NeedInputList:[],
            //保存信息
            Money:''

        }
    },
    created(){
        this.initThisPage();
        this.queryTheme();

    },
    methods:{
        initThisPage(){
            var self = this;
            $.ajax({
                url: "./goLogin/initIndexPage", //请求的url地址
                xhrFields: {
                    withCredentials: true
                },
                async:false,
                dataType: "json", //返回格式为json
                type: "GET", //请求方式
                processData: false, //对表单data数据是否进行序列化
                contentType: false, //dataType设置你收到服务器数据的格式
                headers: {
                    'Content-Type': 'application/json'
                },
                beforeSend: function() {
                    //请求前的处理
                },
                success: function(data) {
                    if(data.Status==0){
                        // top.location.href = "../../login.html";
                        window.location.href="../../login.html";
                    }else if(data.Status=1){
                        if(data.Store=='运营管理中心'&&data.Lim==0){
                            self.SelectInfo.nowdate = data.nowdate;
                            self.SelectInfo.UserNo = data.UserNo;
                            self.SelectInfo.UserName = data.UserName;
                        }else{
                            $("#StoreLim").attr("disabled", true);
                            $("#BmLim").attr("disabled", true);
                            self.SelectInfo.nowdate = data.nowdate;
                            self.SelectInfo.Store = data.Store;
                            self.SelectInfo.Bm = data.Bm;
                            if(self.SelectInfo.Bm=='财务'){
                                self.SelectInfo.Bm = "财务科";
                            }
                            self.SelectInfo.UserNo = data.UserNo;
                            self.SelectInfo.UserName = data.UserName;
                            if(data.Bm=="副总"){
                                self.queryNeedInputInfo();
                            }

                        }
                    }
                },
                complete: function() {
                    //请求完成的处理
                },
                error: function() {}
            });
        },
        queryNeedInputInfo(){
            var self = this;
            var nowdate = self.SelectInfo.nowdate;
            var Store = self.SelectInfo.Store;
            var Bm = self.SelectInfo.Bm;
            var UserNo = self.SelectInfo.UserNo;
            var UserName = self.SelectInfo.UserName;
            var jsondata = {
                "nowdate":nowdate,
                "Store":Store,
                "Bm":Bm,
                "UserNo":UserNo,
                "UserName":UserName,
            }
            var data_json = JSON.stringify(jsondata);
            $.ajax({
                url: "./goProject/queryNeedInputInfo", //请求的url地址
                xhrFields: {
                    withCredentials: true
                },
                dataType: "json", //返回格式为json
                data: data_json, //参数值
                type: "POST", //请求方式
                headers : {
                    'Content-Type' : 'application/json'
                },
                beforeSend: function() {
                    //请求前的处理
                },
                success: function(data) {
                    self.NeedInputList = data.ResultList;
                },
                complete: function() {
                    //请求完成的处理
                },
                error: function(data) {

                }
            });
        },
        queryTheme(){
            var self = this;
            $.ajax({
                url: "./goProject/queryTheme", //请求的url地址
                xhrFields: {
                    withCredentials: true
                },
                dataType: "json", //返回格式为json
                type: "GET", //请求方式
                headers : {
                    'Content-Type' : 'application/json'
                },
                beforeSend: function() {
                    //请求前的处理
                },
                success: function(data) {
                    var ThemeList = data.ThemeList;
                    for(var i=0;i<ThemeList.length;i++){
                        var temp = {
                            value: ThemeList[i].ThemeName,
                            label: ThemeList[i].ThemeName
                        };
                        self.ThemeList.push(temp)
                    }
                },
                complete: function() {
                    //请求完成的处理
                },
                error: function(data) {

                }
            });
        },
        changeNeedInput(){
            var self = this;
            self.queryNeedInputInfo();
        },
        saveServiceInfo(ID,ParentID,Money){
            var self = this;
            var nowdate = self.SelectInfo.nowdate;
            if(nowdate==""||nowdate==null){
                toastr.warning("请选择时间");
                return false;
            }else{
                var tempnowdate = new Date(nowdate);
                nowdate = tempnowdate.toLocaleDateString();
            }
            var Store = self.SelectInfo.Store;
            if(Store==""||Store==null){
                toastr.warning("请选择店面");
                return false;
            }
            var Bm = self.SelectInfo.Bm;
            var UserNo = self.SelectInfo.UserNo;
            var UserName = self.SelectInfo.UserName;
            var Theme = self.SelectInfo.Theme;
            if(Theme==""||Theme==null){
                toastr.warning("请选择活动主题");
                return false;
            }
            if(Money==""||Money==null){
                toastr.warning("请录入金额");
                return false;
            }else{
                if(self.isPositiveInteger(Money)){

                }else{
                    toastr.warning("金额请录入正整数");
                    return false;
                }
            }

            var jsondata = {
                "PID":ID,
                "Money":Money,
                "nowdate":nowdate,
                "Store":Store,
                "Bm":Bm,
                "UserNo":UserNo,
                "UserName":UserName,
                "Theme":Theme
            }
            var data_json = JSON.stringify(jsondata);
            $.ajax({
                url: "./goProject/saveServiceInfo", //请求的url地址
                xhrFields: {
                    withCredentials: true
                },
                dataType: "json", //返回格式为json
                data: data_json, //参数值
                type: "POST", //请求方式
                headers : {
                    'Content-Type' : 'application/json'
                },
                beforeSend: function() {
                    //请求前的处理
                },
                success: function(data) {
                    if(data.Status==1){
                        toastr.success("保存成功");
                    }else{
                        toastr.error("保存失败，请刷新页面后重试");
                    }
                },
                complete: function() {
                    //请求完成的处理
                },
                error: function(data) {

                }
            });
        },
        isMianJi(mj){
            var reg = /^[1-9]+\d*(\.\d{0,2})?$|^0?\.\d{0,2}$/;
            if(reg.test(mj)){
                return true;
            }else{
                return false;
            }
        },
        //正整数验证
        isPositiveInteger(s){//是否为正整数
            var re = /^[0-9]+$/ ;
            return re.test(s)
        }
    }
})